package org.example.struct.array;

import java.util.HashMap;
import java.util.Map;

/**
 * @author liyishan
 * @date 2023/12/5 10:56
 * @apiNote
 */

public class Test00387FirstUniqChar {

    public int firstUniqChar(String s) {
        char[] chars = s.toCharArray();
        Map<Character,Integer> map = new HashMap<>();
        for(char c : chars){
            map.put(c,map.getOrDefault(c,0)+1);
        }
        for(int i = 0; i < chars.length; i++){
            if(map.get(chars[i]) == 1) {
                return i;
            }
        }
        return -1;
    }
}
